package net.ifilm.controller;

import net.ifilm.common.Constants;
import net.ifilm.common.cache.ICache;
import net.ifilm.entity.*;
import net.ifilm.service.FilmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class IndexPageController {

    @Autowired
    private FilmService filmService;

    @RequestMapping(value="/index", method=RequestMethod.GET)
    public String index(HttpServletRequest request) {
        /*
         * 排行列表
         */
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("sortColumn", "playnum");
        parameters.put("limit", 10);
        parameters.put("type", 1);
        List<Film> playNumFlims = filmService.queryFilmOrderPlayNum(parameters);        // 电影排行
        request.setAttribute("playNumFlims", playNumFlims);
        parameters.put("type", 4);
        List<Film> playNumFlimTypes = filmService.queryFilmOrderPlayNum(parameters);    // 动漫排行
        request.setAttribute("playNumFlimTypes", playNumFlimTypes);
        parameters.put("type", 2);
        List<Film> playNumTVs = filmService.queryFilmOrderPlayNum(parameters);          // 电视剧排行
        request.setAttribute("playNumTVs", playNumTVs);
        parameters.put("type", 3);
        List<Film> playNumGames = filmService.queryFilmOrderPlayNum(parameters);        // 综艺排行
        request.setAttribute("playNumGames", playNumGames);

        /*
         * 首页随机10条高清推荐
         */
        parameters.clear();
        parameters.put("roundNum", 10);
        parameters.put("type", 1);
        List<Film> clearFilmlist = filmService.roundQueryFilm(parameters);
        request.setAttribute("clearFilmlist", clearFilmlist);

        parameters.clear();
        parameters.put("limit", 10);
        parameters.put("sortColumn", "createtime");
        // 最新电视剧更新
        parameters.put("type", 2);
        List<Film> newUpdTVList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("newUpdTVList", newUpdTVList);
        // 最新综艺节目更新
        parameters.put("type", 3);
        List<Film> newUpdVarietyList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("newUpdVarietyList", newUpdVarietyList);
        // 最新动漫更新
        parameters.put("type", 4);
        List<Film> newUpdCartoonList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("newUpdCartoonList", newUpdCartoonList);
        // 最新电影更新
        parameters.put("type", 1);
        List<Film> newUpdFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("newUpdFilmList", newUpdFilmList);


        parameters.put("sortColumn", "playnum");
        parameters.put("limit", 20);
        parameters.put("sortColumnSecond", "createtime");
        parameters.put("filmTypeId", 1); // 动作片
        List<Film> actionFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("actionFilmList", actionFilmList);
        parameters.put("filmTypeId", 2); // 喜剧片
        List<Film> comedyFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("comedyFilmList", comedyFilmList);
        parameters.put("filmTypeId", 3); // 爱情片
        List<Film> loveyFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("loveyFilmList", loveyFilmList);
        parameters.put("filmTypeId", 6); // 科幻片
        List<Film> scienceFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("scienceFilmList", scienceFilmList);
        parameters.put("filmTypeId", 100); // 灾难片
        List<Film> disasterFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("disasterFilmList", disasterFilmList);
        parameters.put("filmTypeId", 4); // 惊悚片
        List<Film> thrillerFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("thrillerFilmList", thrillerFilmList);
        parameters.put("filmTypeId", 7); // 悬疑片
        List<Film> suspenseFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("suspenseFilmList", suspenseFilmList);
        parameters.put("filmTypeId", 8); // 记录片
        List<Film> documentaryFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("documentaryFilmList", documentaryFilmList);
        parameters.put("filmTypeId", 9); // 战争片
        List<Film> warFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("warFilmList", warFilmList);
        parameters.put("filmTypeId", 12); // 剧情片
        List<Film> dramaFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("dramaFilmList", dramaFilmList);

        /*
         * 院线大片
         */
        parameters.remove("filmTypeId");
        parameters.remove("sortColumnSecond");
        parameters.put("limit", 10);
        parameters.put("level", 1);
        parameters.put("sortColumn", "createtime");
        List<Film> hotFilmList = filmService.queryFilmOrderPlayNum(parameters);
        request.setAttribute("hotFilmList", hotFilmList);


        // 查询前20条热门关键字列表
        parameters.clear();
        parameters.put("sortColumn", "num");
        parameters.put("limit", 20);
        List<HotKeyword> hotKeywordList = filmService.queryHotKeywordList(parameters);
        request.setAttribute("hotKeywordList", hotKeywordList);

        // 午夜影院随机10条
        parameters.clear();
        int filmTypeId = Constants.switchSex ? 99 : 4; // 99伦理片；4惊悚片
        parameters.put("limit", 14);
        parameters.put("filmTypeId", filmTypeId);
        List<Film> sexFilmList = filmService.findFilm(parameters);
        request.setAttribute("sexFilmList", sexFilmList);

        // 上升最快
        parameters.clear();
        parameters.put("roundNum", 10);
        List<Film> upFastFilmList = filmService.roundQueryFilm(parameters);
        request.setAttribute("upFastFilmList", upFastFilmList);

        return "page/homePage.jsp";
    }

} ///:~

